import { defineStore } from 'pinia'

export const useUser = defineStore('users', {
  state: () => ({
    // 登录状态
    loginStatus: false,
    // token
    token: null,
    // 用户信息
    userInfo: {},
  }),
  actions: {
    // 登录
    login(userinfo) {
      this.userInfo = userinfo
      this.loginStatus = true
      this.token = userinfo.token
    },
    // 退出登录
    logout() {
      this.userInfo = {}
      this.loginStatus = false
      this.token = null
    },
  },
  // 开启持久化存储
  persist: {
    storage: localStorage,
  },
})
